home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / wot-20080519-fx.xpi / chrome / wot.jar / content / api / update.js < prev   
Text File  |  2008-02-21  |  2KB  |  96 lines

  1. /*
  2.     api/update.js
  3.  
  4.     Copyright ┬⌐ 2005, 2006, 2007  Against Intuition, Inc. <info@mywot.com>
  5. */
  6.  
  7. var wot_api_update =
  8. {
  9.     init: function()
  10.     {
  11.     },
  12.  
  13.     send: function()
  14.     {
  15.         try {
  16.             if (WOT_VERSION == wot_prefs.last_version &&
  17.                     Date.now() - Number(wot_prefs.update_checked) <
  18.                         WOT_INTERVAL_UPDATE_CHECK) {
  19.                 return;
  20.             }
  21.  
  22.             /* Increase the last check time a notch */
  23.             wot_prefs.setChar("last_version", WOT_VERSION);
  24.             wot_prefs.setChar("update_checked",
  25.                 (Date.now() - WOT_INTERVAL_UPDATE_CHECK +
  26.                     WOT_INTERVAL_UPDATE_ERROR).toString());
  27.  
  28.             /* Build a request */
  29.             var request = new XMLHttpRequest();
  30.  
  31.             request.open("GET", WOT_SERVICE_NORMAL +
  32.                 WOT_SERVICE_API_UPDATE +
  33.                 "?id="        + wot_prefs.witness_id +
  34.                 "&nonce="    + wot_crypto.nonce() +
  35.                 "&lang="    + wot_util.getstring("language") +
  36.                 "&version="    + WOT_PLATFORM + "-" + WOT_VERSION);
  37.  
  38.             new wot_cookie_remover(request);
  39.  
  40.             request.onload = this.onload;
  41.             request.send(null);
  42.         } catch (e) {
  43.             dump("wot_api_update.send: failed with " + e + "\n");
  44.         }
  45.     },
  46.  
  47.     onload: function(event)
  48.     {
  49.         try {
  50.             if (!event || !event.target ||  event.target.status != 200) {
  51.                 return;
  52.             }
  53.  
  54.             /* Update the the last check time */
  55.             wot_prefs.setChar("update_checked", Date.now().toString());
  56.  
  57.             var update = null;
  58.             var tags =
  59.                 event.target.responseXML.getElementsByTagName(WOT_PLATFORM);
  60.  
  61.             if (tags) {
  62.                 update = tags.item(0);
  63.             }
  64.  
  65.             if (!update) {
  66.                 return;
  67.             }
  68.  
  69.             /* Version */
  70.             var version = null;
  71.  
  72.             if (update.attributes) {
  73.                 version = update.attributes.getNamedItem(
  74.                             WOT_SERVICE_XML_UPDATE_VERSION);
  75.             }
  76.  
  77.             if (version && version.nodeValue) {
  78.                 wot_prefs.setChar("update_version",    version.nodeValue);
  79.                 wot_core.update();
  80.             }
  81.  
  82.             /* Search rules */
  83.             var search = event.target.responseXML.getElementsByTagName(
  84.                                 WOT_SERVICE_XML_UPDATE_SEARCH);
  85.  
  86.             if (search) {
  87.                 wot_search.parse(search);
  88.             }
  89.         } catch (e) {
  90.             dump("wot_api_update.onload: failed with " + e + "\n");
  91.         }
  92.     }
  93. };
  94.  
  95. wot_api_update.init();
  96.